weiXinController.controller('slrOrderCreateCtl',['$scope','$state','$stateParams','$timeout','$interval','$compile','$rootScope',function($scope,$state,$stateParams,$timeout,$interval,$compile,$rootScope) {
    // 测试$scope.$apply使用
    $scope.title = '新建申领单';

    $scope.materiel_type = 'IN';

    // 显示账外/账内备件 => OUT/IN
    $scope.materiel_account_type = 'OUT';

    // 审批方式 => COMMON/URGENT
    $scope.approval_type = 'COMMON';

    //类型 => OUT/BORROW
    $scope.type = 'OUT';

    // 账外冲销备件列表
    $scope.materiel_out_in_list = [];

    // 账内冲销备件列表
    $scope.materiel_in_in_list = [];

    //仓库id
	$scope.warehouse_info_id;

	//
    $scope.warehouse_show;

    $scope.clearText = function (id) {
        console.log(id);
        $scope.spSearch = {};
        $scope.batchCode = "";
        $scope.rfidNumber = "";
        if (id == "9") {
            return
        }
        $("#" + id).modal('hide');
    };

    //类型
    var lastValue;
    $('#type').on('focus', function () {
        lastValue = this.value;
    }).change(function() {
        if($scope.materiel_out_in_list.length > 0 || $scope.materiel_in_in_list.length > 0){
            layer.confirm('更换类型后将会清除所有备件列表', {
                btn: ['更换','不更换']
            }, function(){
                var type = $('#type').val();
                $scope.$apply(function () {
                    $scope.type = type;
                });
                $scope.$apply(function(){
                    $scope.materiel_out_in_list = [];
                    $scope.materiel_in_in_list = [];
                });
                layer.closeAll();
            }, function(){
                $('#type').val(lastValue);
            });
        }else{
            var type = $('#type').val();
            $scope.$apply(function () {
                $scope.type = type;
            });
        }
        console.info($scope.type);
    });

    //帐内帐外
    $('#materiel_account_type').on('change',function(){
        var materiel_account_type = $('#materiel_account_type').val();
        $scope.$apply(function(){
            $scope.materiel_account_type = materiel_account_type;
        });
        if(materiel_account_type == 'IN'){
            $("#approval_type").empty();
            $("#approval_type").prepend("<option value='URGENT'>紧急</option>");
            $("#approval_type").val('URGENT');

        }else{
            $("#approval_type").empty();
            $("#approval_type").prepend("<option value='URGENT'>紧急</option>");
            $("#approval_type").prepend("<option value='COMMON'>正常</option>");
            $("#approval_type").val('COMMON');
        }
        $scope.$apply(function(){
            $scope.approval_type = $("#approval_type").val();
        });
    });

    //审批方式
    $('#approval_type').on('change',function() {
        var approval_type = $('#approval_type').val();
        $scope.$apply(function () {
            $scope.approval_type = approval_type;
        });
    });


    // 仓库分页初始化条件
    var warehousePageParam = {
        id : 'warehouseTable',
        checkbox:false,
        column : [
            {
                type:'rowNum',
                title:'编号',
            },{
                type:'key',
                mapping:'id',
                show:false
            },{
                mapping:'name',
                title:'名称'
            },
            // {
            //     mapping:'status',
            //     title:'状态',
            //     trans : function(data){
            //         if(data.status == 'FREE') {
            //             return "空闲";
            //         } else if(data.status == 'INBOUND') {
            //             return "入库中";
            //         } else if(data.status == 'CHECKING') {
            //             return "盘点中";
            //         } else if(data.status == 'INBOUND_HANG') {
            //             return "入库挂起";
            //         } else if(data.status == 'CHECKING_HANG') {
            //             return "盘点挂起中";
            //         } else if(data.status == 'OUTBOUND') {
            //             return "出库中";
            //         }
            //         return data.status;
            //     }
            // },
            {
                type: 'function',
                title: '操作',
                titleDivStyle: 'text-align: center',
                dataDivStyle: 'text-align: center',
                func: [{
                    title: '选择',
                    css: 'btn-sm btn-outline-info',
                    text111: '<i class="fas fa-check"></i>',
                    text: '选择',
                    func: function (data) {
                        $scope.callBackSelectWarehouseModal(data);
                    }
                }]
            }
        ],
		pageConfig:{
			showGoNum:false
		},
        pageSize:[[5],10,50,100],
        page:function(cmd, currentPage, pageSize, totalPageNum){
            if('first' === cmd){
                currentPage = 1;
            }else if('prev' === cmd){
                currentPage--;
            }else if('next' === cmd){
                currentPage++;
            }else if('last' === cmd){
                currentPage = totalPageNum;
            }else if('change' === cmd){
                currentPage = 1;
            }
            $scope.warehousePageSearch(currentPage,pageSize);
        }
    };
    EdeyeAdmin.initDataTablePhone(warehousePageParam, {data:[]});

    $scope.warehousePageSearch = function(currentPage,pageSize){
        var postData = {};
        postData.currentPage = (currentPage === undefined ? 1 : currentPage);
        postData.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(spPageParam.id) : pageSize);
        EdeyeAdmin.post({
            url:'/warehouse/page',
            data:postData,
        },{
            SUCCESS:function(ret){
                $scope.d = ret.data.data;
                EdeyeAdmin.setDataTableDataPhone(warehousePageParam, ret.data);
            }
        });
    }

    var war = localStorage.getItem('warehouse');
    if(war == null){
        EdeyeAdmin.post({
            url:'/warehouse/page',
            data:{currentPage:1, pageSize:10},
        },{
            SUCCESS:function(ret){
                $scope.warehouse_info_id = ret.data.data[0].id;
                $scope.warehouse_show = ret.data.data[0].name;
                $scope.$apply();
                EdeyeAdmin.setDataTableDataPhone(warehousePageParam, ret.data);
            }
        });
    }else {
        war = JSON.parse(war);
        $scope.warehouse_info_id = war.id;
        $scope.warehouse_show = war.name;
    }


    // 弹出仓库的modal
    $scope.openSelectWarehouseModal = function(){
        if($scope.materiel_out_in_list.length > 0 || $scope.materiel_in_in_list.length > 0){
            layer.confirm('更换仓库后将会清除所有备件列表', {
                btn: ['更换','不更换']
            }, function(){
                $scope.warehousePageSearch();
                $('#selectWarehouseModal').modal('show');
                $scope.$apply(function(){
                    $scope.materiel_out_in_list = [];
                    $scope.materiel_in_in_list = [];
                });
                layer.closeAll();
            }, function(){
            });
        }else{
            $scope.warehousePageSearch();
            $('#selectWarehouseModal').modal('show');
        }

    }

    // 选择仓库后数据回填,并关闭modal
    $scope.callBackSelectWarehouseModal = function(data){
        $scope.$apply(function(){
            $scope.warehouse_info_id = data.id;
            $scope.warehouse_show = data.name;
        });
        $('#selectWarehouseModal').modal('hide');
        $scope.clearText("9");
    }

    // 相关说明
    $scope.showDes = function(){
        layer.open({
            type: 1,
            skin: 'layui-layer-rim',
            area: ['420px', '240px'],
            title: '说明',
            content: `
				<div class="row" style="margin-left: 0px; margin-right: 0px; background-color: white;">
					<div class="col-sm-12 mt-3 mb-3">
						申领单没有冲销类型的借出申领单:<br />
						实际数量<系统记录数量<br /><br />
						冲销会在后台解绑相关硬件<br />
					</div>
				</div>
				`
        });
    }



    // 切换账外账内显示
    $('#type_account').on('change',function(){
        var type_account_new = $('#type_account').val();
        $scope.$apply(function(){
            $scope.materiel_account_type = type_account_new;
        });
    });

    // 准备添加的备件绑定信息(modal中展示)
    $scope.bind_info = {
        sp_code:'',
        batch_code:'',
        type:'',
        unit:'',
        num:0,
    }

    var scrollTop;

    // 弹出入库单备件新增modal
    $scope.addStoreMaterielModal = function(){
        if(!$scope.warehouse_info_id){
            EdeyeAdmin.closeMsg('请选择仓库',true,1);
            return;
        }
        $('#addStoreMaterielModal').modal({backdrop: 'static', keyboard: false});

        scrollTop = document.scrollingElement.scrollTop;
        EdeyeAdmin.stopScroll(scrollTop);
        $('#number').blur(function () {
           EdeyeAdmin.openScroll(scrollTop);
        });
    }

    // 关闭入库单新增modal
    $scope.closeStoreMaterielModal = function(){
        $scope.bind_info = {
            sp_code:'',
            batch_code:'',
            type:'',
            unit:'',
            num:0,
        }
        $('#addStoreMaterielModal').modal('hide');
        $scope.clearText("9");
    }
    $scope.spSearch = {
        spCode: '',
        spName: '',
        type: '',
        borrow: ''
    }
    // sp 数据获取
    $scope.spPageSearch = function(currentPage,pageSize){
    	EdeyeAdmin.setDataTableDataPhone(spPageParam, {data:[]});
        var postData = {materiel_account_type:$scope.materiel_account_type, warehouse_info_id:$scope.warehouse_info_id};
        postData.currentPage = (currentPage === undefined ? 1 : currentPage);
        postData.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(spPageParam.id) : pageSize);
        postData.spCode = $scope.spSearch.spCode;
        postData.spName = $scope.spSearch.spName;
        postData.type = $scope.spSearch.type;
        postData.borrow = $scope.spSearch.borrow;

        EdeyeAdmin.openMsg('查询中,请稍后',true);
        
        EdeyeAdmin.post({
            url:'/orderInfo/getAllMaterielGt0PageByWarehouseId',
            data:postData
        },{
            SUCCESS:function(ret){
                if(ret.code === '200'){
                    $scope.prefix = ret.prefix;
                    EdeyeAdmin.setDataTableDataPhone(spPageParam, ret.data);
                    layer.closeAll();
                }else{
                    layer.closeAll();
                }
            }
        });
    }

    // SP号分页初始化条件
    var spPageParam = {
        id : 'spTable',
        checkbox:false,
        column : [
			{
				type:'rowNum',
				title:'编号',
			},{
				type:'key',
				mapping:'id',
				show:false
			},{
				mapping:'name',
				title:'名称',
				show:true
			},{
				mapping:'unit',
				title:'单位',
				show:true
			},{
				mapping:'sp_code',
				title:'CP编号'
			},{
				mapping:'type',
				title:'分类类型',
				trans : function(data){
					if(data.type == 'WEIGHT') {
						return "称重";
					} else if(data.type == 'QR') {
						return "二维码";
					}
					return data.type;
				}
			},{
				mapping:'borrow',
				title:'能否借用',
                trans:function(data){
                	if(data.borrow === 'CAN'){
                		return '可以借用';
                	}
                	if(data.borrow === 'CANT'){
                		return '不可借用';
                	}
                }
			},{
                type: 'function',
                title: '操作',
                titleDivStyle: 'text-align: center',
                dataDivStyle: 'text-align: center',
                func: [{
                    title: '选择',
                    css: 'btn-sm btn-outline-info',
                    text111: '<i class="fas fa-check"></i>',
                    text: '选择',
                    func: function (data) {
                        if($scope.type == "BORROW" && data.borrow == "CANT"){
                            EdeyeAdmin.closeMsg("借出申领单不能选择此备件",true,1);
                            return;
                        }
                        $scope.callBackSelectSpModal(data);
                    }
                }]
            }
		],
		pageConfig:{
			showGoNum:false
		},
        pageSize:[[5],10,50,100],
        page:function(cmd, currentPage, pageSize, totalPageNum){
            if('first' === cmd){
                currentPage = 1;
            }else if('prev' === cmd){
                currentPage--;
            }else if('next' === cmd){
                currentPage++;
            }else if('last' === cmd){
                currentPage = totalPageNum;
            }else if('change' === cmd){
                currentPage = 1;
            }
            $scope.spPageSearch(currentPage,pageSize);
        }
    };
    EdeyeAdmin.initDataTablePhone(spPageParam, {data:[]});

    // 弹出SP号的modal
    $scope.openSelectSpModal = function(){
        $scope.spPageSearch();
        $('#selectSpModal').modal('show');
    }

    // 选择SP号后数据回填,并关闭modal
    $scope.callBackSelectSpModal = function(data){
        // layer.confirm('更换SP号后将会重新绑定', {
        //     btn: ['更换','不更换']
        // }, function(){
            $scope.$apply(function(){
                $scope.bind_info.sp_code = data.sp_code;
                $scope.bind_info.type = data.type;
                if($scope.bind_info.type === 'WEIGHT'){
                    $scope.bind_info.type_view = '称重';
                }
                if($scope.bind_info.type === 'QR'){
                    $scope.bind_info.type_view = '二维码';
                }
                if($scope.bind_info.type === 'RFID'){
                    $scope.bind_info.type_view = data.type;
                }
                if($scope.materiel_type === 'IN'){

                }

                $scope.bind_info.batch_code = '';
                $scope.bind_info.unit = data.unit;
            });
            layer.closeAll();
        // }, function(){
        // });
    	EdeyeAdmin.setDataTableDataPhone(spPageParam, {data:[]});
        $('#selectSpModal').modal('hide');
        $scope.clearText("9");
    }


    // 批次号分页初始化条件
    var batchPageParam = {
        id : 'batchTable',
        checkbox:false,
        column : [
            {
                type:'rowNum',
                title:'编号',
            },{
                type:'key',
                mapping:'id',
                show:false
            },{
                mapping:'batch_code',
                title:'批次号'
            },{
                type: 'function',
                title: '操作',
                titleDivStyle: 'text-align: center',
                dataDivStyle: 'text-align: center',
                func: [{
                    title: '选择',
                    css: 'btn-sm btn-outline-info',
                    text111: '<i class="fas fa-check"></i>',
                    text: '选择',
                    func: function (data) {
                        $scope.callBackSelectBatchModal(data);
                    }
                }]
            }
        ],
		pageConfig:{
			showGoNum:false
		},
        pageSize:[[5],10,50,100],
        page:function(cmd, currentPage, pageSize, totalPageNum){
            if('first' === cmd){
                currentPage = 1;
            }else if('prev' === cmd){
                currentPage--;
            }else if('next' === cmd){
                currentPage++;
            }else if('last' === cmd){
                currentPage = totalPageNum;
            }else if('change' === cmd){
                currentPage = 1;
            }
            $scope.batchPageSearch(currentPage,pageSize);
        }
    };
    EdeyeAdmin.initDataTablePhone(batchPageParam, {data:[]});

    $scope.batchPageSearch = function(currentPage,pageSize){
        EdeyeAdmin.setDataTableDataPhone(batchPageParam, {data:[]});
        var postData = {materiel_account_type:$scope.materiel_account_type,sp_code:$scope.bind_info.sp_code,warehouse_info_id:$scope.warehouse_info_id};
        postData.currentPage = (currentPage === undefined ? 1 : currentPage);
        postData.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(batchPageParam.id) : pageSize);
        EdeyeAdmin.post({
            url:'/orderInfo/getAllMaterielTypeStockGt0PageByWarehouseId',
            data:postData
        },{
            SUCCESS:function(ret){
                if(ret.code === '200'){
                    $scope.prefix = ret.prefix;
                    EdeyeAdmin.setDataTableDataPhone(batchPageParam, ret.data);
                }
            }
        });
    }

    // 弹出批次号号的modal
    $scope.openSelectBatchModal = function(){
        if($scope.bind_info.sp_code.length < 1){
            EdeyeAdmin.closeMsg('请先选择CP号',true,1);
            return;
        }
        $scope.batchPageSearch();
        $('#selectBatchModal').modal('show');
    }

    // 选择批次号号后数据回填,并关闭modal
    $scope.callBackSelectBatchModal = function(data){
        $scope.$apply(function(){
            $scope.bind_info.batch_code = data.batch_code;
        });
        EdeyeAdmin.setDataTableDataPhone(batchPageParam, {data:[]});
        $('#selectBatchModal').modal('hide');
        $scope.clearText("9");
    }

    // 多层modal必须使用这个方法,否则会造成上1层的modal失去滚动条
    $('#selectSpModal,#selectBatchModal,#selectShelfModal,#selectRfidModal,#selectBasketModal').on('hidden.bs.modal', function (event) {
        $("body").addClass("modal-open");
    });


    // 新增入库单备件并关闭modal
    $scope.addStoreMateriel = function(){
        $scope.clearText("9");
        // 实际/冲销校验SP号,批次号,新增数量
        var ret = EdeyeAdmin.checkKit.finalCheck($scope.bind_info, true, {
            'sp_code': {
                method: 'strRange',
                methodParam: ['&&', ['>=', 1], ['<=', 128]],
                msg: '请选择CP号'
            },
            'batch_code': {
                method: 'strRange',
                methodParam: ['&&', ['>=', 1], ['<=', 128]],
                msg: '请选择批次号'
            },
            'num': {
                method: 'integerRange',
                methodParam: ['&&', ['>=', 1], ['<=', 1000000]],
                msg: '申领数量为1~1000000的正整数'
            }
        });
        if (!ret.flag) {
            EdeyeAdmin.closeMsg(ret.msg.join('<br />'), false, 1);
            return;
        }

    	var param = $scope.bind_info;
    	param.warehouse_id = $scope.warehouse_info_id;
    	
        EdeyeAdmin.post({
            url: '/materielInfo/compareOrderNum',
            data: param
        }, {
            SUCCESS: function (ret) {
                var storeNum = Number(ret.data);
                var writeNum = $scope.bind_info.num;
                if(storeNum < writeNum){
                	layer.confirm('库存不足,是否继续', {
                         btn: ['是','否']
                	}, function(){
                        var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';

                        var containFlag = false;
                        
                        for(var tmpKey in $scope[listName]){
                        	var tmpObj = $scope[listName][tmpKey];
                        	if(tmpObj.sp_code === $scope.bind_info.sp_code && tmpObj.batch_code === $scope.bind_info.batch_code){
                            	$scope[listName][tmpKey].num += $scope.bind_info.num;
                            	containFlag = true;
                        	}
                        }

                        if(!containFlag){
                            $scope[listName].push({
                                id:moment().format('YYMMDDHHmmssSSS'),
                                sp_code:$scope.bind_info.sp_code,
                                batch_code:$scope.bind_info.batch_code,
                                type:$scope.bind_info.type,
                                num:$scope.bind_info.num,
                                unit:$scope.bind_info.unit,
                                type_name:($scope.bind_info.type === 'WEIGHT' ? '称重' : ($scope.bind_info.type === 'QR' ? '二维码' : $scope.bind_info.type)),
                            });
                        }
                        
                        $scope.closeStoreMaterielModal();
                        $scope.$apply();
                        layer.closeAll();
                	}, function(){
                        $scope.closeStoreMaterielModal();
                        $scope.$apply();
                	});
                }else{
                    var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';

                    var containFlag = false;
                    
                    for(var tmpKey in $scope[listName]){
                    	var tmpObj = $scope[listName][tmpKey];
                    	if(tmpObj.sp_code === $scope.bind_info.sp_code && tmpObj.batch_code === $scope.bind_info.batch_code){
                        	$scope[listName][tmpKey].num += $scope.bind_info.num;
                        	containFlag = true;
                    	}
                    }

                    if(!containFlag){
                        $scope[listName].push({
                            id:moment().format('YYMMDDHHmmssSSS'),
                            sp_code:$scope.bind_info.sp_code,
                            batch_code:$scope.bind_info.batch_code,
                            type:$scope.bind_info.type,
                            num:$scope.bind_info.num,
                            unit:$scope.bind_info.unit,
                            type_name:($scope.bind_info.type === 'WEIGHT' ? '称重' : ($scope.bind_info.type === 'QR' ? '二维码' : $scope.bind_info.type)),
                        });
                    }
                    
                    $scope.closeStoreMaterielModal();
                    $scope.$apply();
                }
            }
        });
    }

    // 已加入到入库单中的备件查看时的ng1对象
    $scope.materielViewObj = {};

    // 提交入库单
    $scope.submitStore = function(){
        if(!$scope.warehouse_info_id){
            EdeyeAdmin.closeMsg('请选择仓库',true,1);
            return;
        }
        var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';
        if($scope[listName].length < 1){
            EdeyeAdmin.closeMsg('请添加备件',true,1);
            return;
        }

        var warehouse = {
            id : $scope.warehouse_info_id,
            name : $scope.warehouse_show
        }

        localStorage.setItem('warehouse', JSON.stringify(warehouse));
        
        EdeyeAdmin.post({
            url: '/materielInfo/compareOrderNumBatch',
            data: {
                param:$scope[listName]
            }
        }, {
            SUCCESS: function (ret) {
            	var storeObjs = ret.data;
        		var isOK = true;
            	var msg = '';
            	for(var tmpKey in $scope[listName]){
            		var tmpObj = $scope[listName][tmpKey];
            		isOK = false;
            		for(var tmpInnerKey in storeObjs){
            			var storeObj = storeObjs[tmpInnerKey];
            			if(tmpObj.sp_code === storeObj.sp_code && tmpObj.batch_code === storeObj.batch_code){
            				if(tmpObj.num <= storeObj.num){
            					isOK = true;
            					break;
            				}
            			}
            		}
            		if(!isOK){
            			msg = 'CP号(' + tmpObj.sp_code + '),批次号(' + tmpObj.batch_code + ')库存不足(当前库存数:' + storeObj.num + ')'
    					break;
            		}
            	}

        		if(!isOK){
                    EdeyeAdmin.closeMsg(msg,true,3);
        		}else{
        			
        	        layer.confirm('提交或保存申领单', {
        	            btn: ['保存','提交'],
        	            // closeBtn: false
        	        }, function(){
        	            EdeyeAdmin.post({
        	                url: '/orderInfo/createNewOrder',
        	                data: {
        	                    type:$scope.type,
        	                    warehouse_info_id:$scope.warehouse_info_id,
        	                    approval_type:$scope.approval_type,
        	                    materiel_account_type:$scope.materiel_account_type,
        	                    materiel_type:$scope.materiel_type,
        	                    param:$scope[listName]
        	                }
        	            }, {
        	                SUCCESS: function (ret) {
        	                    EdeyeAdmin.closeMsg(ret.msg,true,1);
        	                    $state.go('/slr/order/page');
        	                }
        	            });
        	            layer.closeAll();
        	        }, function () {
        	            EdeyeAdmin.post({
        	                url: '/orderInfo/createNewOrder',
        	                data: {
        	                    type:$scope.type,
        	                    warehouse_info_id:$scope.warehouse_info_id,
        	                    approval_type:$scope.approval_type,
        	                    materiel_account_type:$scope.materiel_account_type,
        	                    materiel_type:$scope.materiel_type,
        	                    param:$scope[listName]
        	                }
        	            }, {
        	                SUCCESS: function (ret) {
        	                    EdeyeAdmin.post({
        	                        url: '/orderInfo/order',
        	                        data: {
        	                            id:ret.order.id,
        	                            warehouse_id:$scope.warehouse_info_id
        	                        }
        	                    }, {
        	                        SUCCESS: function (ret) {
        	                            EdeyeAdmin.closeMsg(ret.msg,true,3);
        	                            $state.go('/slr/order/page');
        	                        }
        	                    });
        	                }
        	            });
        	            layer.closeAll();
        	        });
        			
        		}
            }
        });
    }

    // 移出加入到入库单中的备件
    $scope.removeStoreMateriel = function(id){
        // TODO 二次确认 注释 4月8日
        // layer.confirm('是否将备件从列表中移出?', {
        //         btn: ['确认','取消'],
        //         closeBtn: false
        //     }, function(){
                var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';
                for(var tmpKey in $scope[listName]){
                    if($scope[listName][tmpKey].id === id){
                        // $scope.$apply(function(){
                            $scope[listName].splice(tmpKey, 1);
                        // });
                        break;
                    }
                }
                layer.closeAll();
        //     }, function(){
        //     }
        // );
    }

    // 查看加入到入库单中的备件详情
    $scope.viewStoreMateriel = function(id){
        var listName = 'materiel_' + $scope.materiel_account_type.toLowerCase() + '_' + $scope.materiel_type.toLowerCase() + '_list';
        for(var tmpKey in $scope[listName]){
            if($scope[listName][tmpKey].id === id){
                $scope.materielViewObj = $scope[listName][tmpKey];
                break;
            }
        }
        $('#viewMaterielModal').modal('show');
    }
}]);